package com.order.controller.sys;

import java.util.Map;

import com.order.config.Consts;
import com.order.model.Dish;
import com.order.model.OrderHead;
import com.alibaba.fastjson.JSONObject;
import com.jfinal.core.Controller;
import com.jfinal.ext.render.excel.PoiRender;
import com.jfinal.ext.route.ControllerBind;

/** 
* @ClassName: ReportController 
* @Description: 报表控制器
* @author LinBo
* @date 2014年4月22日 上午11:12:23 
*  
*/ 
@ControllerBind(controllerKey = Consts.SYS + "report")
public class ReportController extends Controller {

	/** 
	* @Title: reportOrder 
	* @Description:    定位订单报表页面
	*/ 
	public void reportOrder(){
		render(Consts.SYS + "report_order.htm");
	}
	
	/** 
	* @Title: reportDish 
	* @Description:    定位菜品报表页面
	*/ 
	public void reportDish(){
		render(Consts.SYS + "report_dish.htm");
	}
	
	/** 
	* @Title: getOrderJson 
	* @Description:    获取订单详情
	*/ 
	public void getOrderJson(){
		String jsonStr = "{\"count\":\"\",\"account_name\":\"\",\"create_date_l\":\"\",\"create_date_r\":\"\"}";
		int page = getParaToInt("page", 0);
		int pageSize = getParaToInt("pagesize", 0);
		//int orderHeadId = getParaToInt("order_head_id", 0);
		//String sortName = getPara("sortname");
		//JSONObject sortJson = JSONObject.parseObject(sortName);
		String sortOrder = getPara("sortorder");
		JSONObject json = JSONObject.parseObject(getPara("where", jsonStr));
		Map<String, Object> map = null;
		map = OrderHead.dao.getOrder2(page, pageSize, json, "", sortOrder);
		renderJson(map);
	}
	
	/** 
	* @Title: getDishJson 
	* @描述:    获取菜品报表
	*/ 
	public void getDishJson(){
		String jsonStr = getPara("json","");
		String orderHeadId = getPara("order_head_id");
		int pageSize = getParaToInt("pageSize", 20);
		int page = getParaToInt("page", 1);
		JSONObject json = JSONObject.parseObject(jsonStr);
		Map<String, Object> map = Dish.dao.getDishMap(page, pageSize, json);
		
		renderJson(map);
	}


	// 导出菜品Excel
	public void getDishExcel() throws Exception {
		String jsonStr = "{}";
		JSONObject jsonObj = JSONObject.parseObject(getPara("where", jsonStr));
		int pagesize = getParaToInt("pagesize", 20);
		int page = getParaToInt("page", 1);
		String file = getPara("file", "");
		PoiRender poiRender = Dish.dao.getExcel(page, pagesize);
		render(poiRender);
	}
	
	//导出订单Excel
	public void getOrderExcel(){
		String jsonStr = "{}";
		JSONObject json = JSONObject.parseObject(getPara("where", jsonStr));
		int page = getParaToInt("page", 1);
		int pageSize = getParaToInt("pageSize", 20);
		PoiRender poiRender = OrderHead.dao.getExcel(page, pageSize, json);
		System.out.println(poiRender);
		render(poiRender);
	}
	
	
}

